package com.woniuxy.microstockserver.mapper;

import com.woniuxy.microstockserver.bean.OutStockBean;
import com.woniuxy.microstockserver.bean.PageRequestBean;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @author 赵雄伟
 * 出库单 mapper
 */
@Mapper
public interface OutStockMapper {
    /**
     *分页、模糊、分类查询所有出库单
     * @param pageRequestBean
     * @param
     * @return
     */
    List<OutStockBean> findAllOutStockBean(@Param("p") PageRequestBean pageRequestBean, @Param("os") OutStockBean OutStockBean);

    /**
     * 新增出库单：含正常出库，销售出库，采购退货出库
     * @param outStockBean
     * @return
     */
    @Insert("insert into t_outstock_info (os_num,fk_osstore_id,os_type,os_amount,os_handle,os_makelist_person,os_makelist_date,os_audit_status,delete_status,os_remarks) values(#{os.osNum},#{os.osStoreId},#{os.osType},#{os.osAmount},#{os.osHandle},#{os.osMakeListPerson},#{os.osMakeListDate},#{os.osAuditStatus},#{os.deleteStatus},#{os.osRemarks})")
    @Options(useGeneratedKeys = true, keyProperty = "os.id" ,keyColumn="id")
    Long saveOutStockBean(@Param("os") OutStockBean outStockBean);


    /**
     * 根据id查询出库单的详情
     * @param id
     * @return
     */
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "osNum",column = "os_num",javaType = String.class),
            @Result(property = "osStoreId",column = "fk_osstore_id",javaType = Long.class),
            @Result(property = "osType",column = "os_type",javaType = Integer.class),
            @Result(property = "osAmount",column = "os_amount",javaType = Integer.class),
            @Result(property = "osHandle",column = "os_handle",javaType = String.class),
            @Result(property = "osMakeListPerson",column = "os_makelist_person",javaType = String.class),
            @Result(property = "osMakeListDate",column = "os_makelist_date",javaType = Date.class),
            @Result(property = "osAuditStatus",column = "os_audit_status",javaType = Integer.class),
            @Result(property = "deleteStatus",column = "delete_status",javaType = Byte.class),
            @Result(property = "osRemarks",column = "os_remarks",javaType = String.class)
    })
    @Select("select * from t_outstock_info where id = #{id}")
    OutStockBean findOutStockAndGoodsDetail(@Param("id") Long id);

    /**
     * 修改出库单
     * @param outStockBean
     * @return
     */
    @Update("<script>" +
            "update t_outstock_info" +
            "<set>" +
            "<if test='os.osNum != null'>" +
            " os_num = #{os.osNum}," +
            "</if>" +
            "<if test='os.osStoreId != null'>" +
            " fk_osstore_id = #{os.osStoreId}," +
            "</if>" +
            "<if test='os.osType != null'>" +
            " es_type = #{os.osType}," +
            "</if>" +
            "<if test='os.osAmount != null'>" +
            " os_amount = #{os.osAmount}," +
            "</if>" +
            "<if test='os.osHandle != null'>" +
            " os_handle = #{os.osHandle}," +
            "</if>" +
            "<if test='os.osMakeListPerson != null'>" +
            " os_makelist_person = #{os.esMakeListPerson}," +
            "</if>" +
            "<if test='os.osMakeListDate != null'>" +
            " os_makelist_date = #{os.osMakeListDate}," +
            "</if>" +
            "<if test='os.osAuditStatus != null'>" +
            " os_audit_status = #{os.osAuditStatus}," +
            "</if>" +
            "<if test='os.deleteStatus != null'>" +
            " delete_status = #{os.deleteStatus}," +
            "</if>" +
            "<if test='os.osRemarks != null'>" +
            " os_remarks = #{os.osRemarks}," +
            "</if>" +
            "</set>" +
            "where id = #{os.id}" +
            "</script>")
    Long upadteOutStockBean(@Param("os") OutStockBean outStockBean);

}
